package com.tale.springbootatm.service;

import com.tale.springbootatm.entity.User;
import com.tale.springbootatm.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Date;

/**
 * author: 蔡奇峰
 * date: 2020/4/11 14:11
 * @Version V1.0
 **/
@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    /**
     * 验证
     * @param bankCard
     * @param password
     * @return
     */
    public User findOne(long bankCard, String password){

        return userRepository.findByBankCardAndPassword(bankCard, password);
    }

    /**
     * 根据卡号查询
     * @param bankCard
     * @return
     */
    public User getOne(long bankCard){
        return userRepository.findByBankCard(bankCard);
    }


    /**
     * 更新账户余额
     * @param bankCard
     * @param balance
     * @return
     */
    public int updateBalance(long bankCard, double balance){

        return userRepository.updateBalance(bankCard, balance);
    }


    /**
     * 更新卡号状态
     * @param bankCard
     * @param type
     * @return
     */
    public int updateType(long bankCard, int type){

        return userRepository.updateType(bankCard, type);
    }

    /**
     * 修改密码
     * @param bankCard
     * @param password
     * @return
     */
    public int updatePassword(long bankCard, String password){

        return userRepository.updatePassword(bankCard, password);
    }

    /**
     * 更新登录时间
     * @param bankCard
     * @param loginDate
     * @return
     */
    @Async
    public int updateLoginDate(long bankCard, Date loginDate){

        return userRepository.updateLoginDate(bankCard, loginDate);
    }
}
